home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 18153 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: trib.apple.com!NewsWatcher!user
  2. From: Andrew_Carol@quickmail.apple.com (Andrew)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Calling the wrong constructor
  5. Date: Thu, 18 Apr 1996 20:00:06 -0800
  6. Organization: Apple Computer, Inc., Cupertino, California
  7. Message-ID: <Andrew_Carol-1804962001240001@17.127.18.252>
  8. References: <4kot87$796@earth.njcc.com>
  9. NNTP-Posting-Host: 17.127.18.252
  10.  
  11. In article <4kot87$796@earth.njcc.com>, mike@pluto.njcc.com (Michael
  12. Hohenshilt) wrote:
  13.  
  14. >   This might seem like a basic question, but lets say you something set u 
  15. > like the following:
  16. > class Parent { Parent() { allocsomething} ~Parent() { deletesomething }... };
  17. > class Foo : Parent { Foo() { allocsomething } ~Foo() {deletesomething }... };
  18. > class Contain { Parent *ptr; ... };
  19. > both parent, and foo allocate memory, and will free it up when being 
  20. > destructed.  Contain just holds a pointer of type Parent, and its 
  21. > constructor takes such a pointer as a parameter.
  22. >   If I store a pointer of type Foo into contain.ptr and discard that 
  23. > pointer.  Is there any way to have contain (via destructors) free up all 
  24. > memory allocated by Foo and/or Parent?
  25.  
  26.  
  27. Assuming that "Contain" keeps a copy of the 'ptr'...
  28.  
  29. ~Contain() { delete ptr; }
  30.  
  31. This will call the destructor of Foo and Parent...
  32.  
  33. Good luck!
  34.  
  35. -- 
  36. Andrew Carol               "Could be worse.  Could be raining."
  37. carol@quickmail.apple.com
  38.